<?php



class important extends connector {

	function important() {
		$this->softbase(true);
	}

	function onarticlelist() {
		$this->powercheck(57, 58);
		parent::start_template();

		$MinPageid = intval($this->fun->accept('MinPageid', 'R'));

		$page_id = intval($this->fun->accept('page_id', 'R'));

		$countnum = intval($this->fun->accept('countnum', 'R'));

		$MaxPerPage = intval($this->fun->accept('MaxPerPage', 'R'));
		if (empty($MaxPerPage)) {
			$MaxPerPage = $this->CON['max_list'];
		}

		$ordersearch = $this->fun->accept('ordersearch', 'R');
		$lng = $this->fun->accept('lng', 'R');
		if (!empty($lng)) {
			$db_where = ' WHERE lng=\'' . $lng . '\'';
		} else {
			$db_where = ' WHERE lng=\'' . $this->CON['default_lng'] . '\'';
		}
		$ishtml = intval($this->fun->accept('ishtml', 'R'));
		if (!empty($ishtml)) {
			if ($ishtml == 2) $ishtml = 0;
			$db_where.=' AND ishtml=' . $ishtml;
		}
		$isorder = intval($this->fun->accept('isorder', 'R'));
		if (!empty($isorder)) {
			if ($isorder == 2) $isorder = 0;
			$db_where.=' AND isorder=' . $isorder;
		}
		$islink = intval($this->fun->accept('islink', 'R'));
		if (!empty($islink)) {
			if ($islink == 2) $islink = 0;
			$db_where.=' AND islink=' . $islink;
		}
		$isclass = intval($this->fun->accept('isclass', 'R'));
		if (!empty($isclass)) {
			if ($isclass == 2) $isclass = 0;
			$db_where.=' AND isclass=' . $isclass;
		}
		$mid = intval($this->fun->accept('mid', 'R'));
		if (!empty($mid)) {
			$db_where.=' AND mid=' . $mid;
		}
		$sid = intval($this->fun->accept('sid', 'R'));
		if (!empty($sid)) {
			$db_where.=' AND sid=' . $sid;
		}
		$tid = intval($this->fun->accept('tid', 'R'));
		if (!empty($tid)) {
			$db_where.=' AND ' . $this->get_typeid($tid, 'tid', 0, $mid, 0, $lng);
		}
		$dlid = $this->fun->accept('dlid', 'R');
		if (!empty($dlid)) {
			$db_where.=" AND FIND_IN_SET('$dlid',recommend)";
		}
		$serchekey = $this->fun->accept('serchekey', 'R');
		if (!empty($serchekey)) {
			$db_where.=" AND title like '%$serchekey%'";
		}

		$limitkey = $this->fun->accept('limitkey', 'R');
		$limitkey = empty($limitkey) ? 'did' : $limitkey;

		$limitclass = $this->fun->accept('limitclass', 'R');
		$limitclass = empty($limitclass) ? 'DESC' : $limitclass;
		$db_table = db_prefix . 'document';
		if (!empty($countnum)) {
			$countnum = $this->db_numrows($db_table, $db_where);
			exit($countnum);
		}
		$sql = 'SELECT * FROM ' . $db_table . $db_where . ' ORDER BY ' . $limitkey . ' ' . $limitclass . ' LIMIT ' . $MinPageid . ',' . $MaxPerPage;
		$rs = $this->db->query($sql);
		while ($rsList = $this->db->fetch_assoc($rs)) {
			$modelname = $this->get_modelview($rsList['mid'], 'modelname');
			$typename = $this->get_type($rsList['tid'], 'typename');
			$rsList['modelname'] = $modelname;
			$rsList['typename'] = $typename;
			$rsList['ctitle'] = empty($rsList['color']) ? $rsList['title'] : "<font color='" . $rsList['color'] . "'>" . $rsList['title'] . "</font>";
			$rsList['readlink'] = $this->get_link('doc', $rsList, $rsList['lng']);
			$array[] = $rsList;
		}
		$this->fun->setcookie($this->fun->noncefile() . 'pgid', $page_id, 600);
		$this->ectemplates->assign('array', $array);
		$this->ectemplates->assign('sql', $sql);

		$outtemplatefile = empty($ordersearch) ? 'article/article_list' : 'order/order_article_list';
		$this->ectemplates->display($outtemplatefile);
	}

	function onajaxarticlelist() {
		parent::start_template();

		$type = $this->fun->accept('type', 'R');
		$type = empty($type) ? 'add' : $type;
		$did = $this->fun->accept('did', 'R');

		$didlist = $this->fun->accept('didlist', 'R');
		if (!empty($didlist)) {
			$didlistArray = explode(',', $didlist);
			$didArray = explode(',', $did);
			foreach ($didArray as $key => $value) {
				if (in_array($value, $didlistArray)) {
					unset($didArray[$key]);
				}
			}
			if (count($didArray) < 1 || empty($didArray)) exit;
			$did = implode(',', $didArray) . ',';
		}
		if (!empty($did)) {
			$db_where = ' WHERE did IN (' . $did . '0)';
		} else {
			exit('err');
		}
		$db_table = db_prefix . 'document';
		$sql = 'SELECT * FROM ' . $db_table . $db_where . ' ORDER BY did DESC';
		$rs = $this->db->query($sql);
		while ($rsList = $this->db->fetch_assoc($rs)) {
			$modelname = $this->get_modelview($rsList['mid'], 'modelname');
			$typename = $this->get_type($rsList['tid'], 'typename');
			$rsList['modelname'] = $modelname;
			$rsList['typename'] = $typename;
			$rsList['readlink'] = admin_URL . $this->CON['file_htmldir'] . $rsList['lng'] . '/' . $rsList['filepath'] . '/' . $rsList['filename'] . '.' . $this->CON['file_fileex'];
			$array[] = $rsList;
		}
		$this->ectemplates->assign('array', $array);
		$templatesfile = ($type == 'edit') ? 'order/order_article_edit_list' : 'order/order_article_form_list';
		$this->ectemplates->display($templatesfile);
	}

	function onlist() {
		parent::start_template();
		$listfunction = $this->fun->accept('listfunction', 'G');
		if (empty($listfunction)) {
			exit('err');
		}
		$tid = intval($this->fun->accept('tid', 'R'));
		$sid = intval($this->fun->accept('sid', 'R'));
		$eqid = intval($this->fun->accept('eqid', 'R'));
		$eqid = empty($eqid) ? 1 : $eqid;
		$lng = $this->fun->accept('lng', 'G');
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;
		$mid = intval($this->fun->accept('mid', 'G'));
		$isclass = intval($this->fun->accept('isclass', 'G'));
		include_once admin_ROOT . adminfile . '/include/command_list.php';

		$cookpage = $this->fun->accept($CONLIST[$listfunction]['pagecoock'], 'C');
		$nowpage = empty($cookpage) ? 0 : $cookpage;
		$this->ectemplates->assign('nowpage', $nowpage);
		$this->ectemplates->assign('loadurl', $CONLIST[$listfunction]['loadurl'] . '&lng=' . $lng . '&tid=' . $tid . '&sid=' . $sid . '&eqid=' . $eqid);

		$this->ectemplates->assign('MaxPerPage', $this->CON['max_list']);

		$this->ectemplates->assign('MaxHit', $this->CON['max_page']);
		$this->ectemplates->assign('listtype', $listtype);
		$this->ectemplates->assign('eqid', $eqid);
		$this->ectemplates->assign('lng', $lng);
		$this->ectemplates->assign('mid', $mid);
		$this->ectemplates->assign('isclass', $isclass);
		$this->ectemplates->assign('listfunction', $listfunction);
		$this->ectemplates->display('article/article_tab_list');
	}

	function ondocaddwindow() {
		parent::start_template();
		$tab = $this->fun->accept('tab', 'R');
		$tab = empty($tab) ? 'true' : $tab;

		$type = intval($this->fun->accept('type', 'R'));
		$type = empty($type) ? 0 : $type;

		$mid = intval($this->fun->accept('mid', 'R'));
		$mid = empty($mid) ? 0 : $mid;

		$lng = $this->fun->accept('lng', 'R');
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;

		$lnglist = $this->get_lng_array($lng);
		$this->ectemplates->assign('lnglist', $lnglist['list']);

		$modelarray = $this->get_model(0, $lng, 1);
		$this->ectemplates->assign('modelarray', $modelarray['list']);
		$this->ectemplates->assign('type', $type);
		$this->ectemplates->display("article/article_add_window");
	}

	function onsearch() {
		parent::start_template();
		$tab = $this->fun->accept('tab', 'R');
		$tab = empty($tab) ? 'true' : $tab;

		$mid = intval($this->fun->accept('mid', 'R'));
		$mid = empty($mid) ? 0 : $mid;

		$lng = $this->fun->accept('lng', 'R');
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;

		$lnglist = $this->get_lng_array($lng);
		$this->ectemplates->assign('lnglist', $lnglist['list']);

		$modelarray = $this->get_model(0, $lng, 1);
		$this->ectemplates->assign('modelarray', $modelarray['list']);
		$this->ectemplates->display("article/article_search");
	}

	function ondocadd() {
		parent::start_template();
		$tab = $this->fun->accept('tab', 'R');
		$tab = empty($tab) ? 'true' : $tab;

		$mid = intval($this->fun->accept('mid', 'R'));
		$mid = empty($mid) ? 0 : $mid;

		$lng = $this->fun->accept('lng', 'R');
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;

		$typelist = $this->get_typeselect($mid, 0, 0, $lng, 0, 1);
		$this->ectemplates->assign('typelist', $typelist);

		$memberpuv = $this->get_member_purview_array();
		$this->ectemplates->assign('memberpuvlist', $memberpuv['list']);

		$attrread = $this->get_modelatt($mid);
		$this->ectemplates->assign('attrread', $attrread);

		$modelview = $this->get_modelview($mid);
		$this->ectemplates->assign('modelview', $modelview);

		$subjectlistarray = $this->get_subjectlist_array(0, $mid, $lng);
		$this->ectemplates->assign('subjectlistarray', $subjectlistarray['list']);

		$formarray = $this->get_form_array(0, $lng);
		$this->ectemplates->assign('formarray', $formarray['list']);

		$keytypearray = $this->get_keytype_array($docview['ktid'], $lng);
		$this->ectemplates->assign('keyarray', $keytypearray['list']);

		$doclabel = $this->get_doclabel_array(0, $mid);
		$this->ectemplates->assign('doclabel', $doclabel['list']);
		$input_default = $this->CON;
		$tsn = $this->fun->get_tsn();
		$this->ectemplates->assign('defaultinput', $input_default);
		$this->ectemplates->assign('lng', $lng);
		$this->ectemplates->assign('path', admin_URL);
		$this->ectemplates->assign('mid', $mid);
		$this->ectemplates->assign('tsn', $tsn);
		$this->ectemplates->assign('tab', $tab);
		$this->ectemplates->assign('startime', $this->fun->formatdate(time(), 2));
		$this->ectemplates->assign('endtime', $this->fun->formatdate(time() + (30 * 24 * 60 * 720), 2));
		$this->ectemplates->display('article/article_add_doc');
	}

	function ondocbatadd() {
		parent::start_template();
		$tab = $this->fun->accept('tab', 'R');
		$tab = empty($tab) ? 'true' : $tab;

		$mid = intval($this->fun->accept('mid', 'R'));
		$mid = empty($mid) ? 0 : $mid;

		$lng = $this->fun->accept('lng', 'R');
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;

		$typelist = $this->get_typeselect($mid, 0, 0, $lng, 0, 1);
		$this->ectemplates->assign('typelist', $typelist);

		$subjectlistarray = $this->get_subjectlist_array(0, $mid, $lng);
		$this->ectemplates->assign('subjectlistarray', $subjectlistarray['list']);
		$input_default = $this->CON;
		$tsn = $this->fun->get_tsn();
		$this->ectemplates->assign('defaultinput', $input_default);
		$this->ectemplates->assign('lng', $lng);
		$this->ectemplates->assign('path', admin_URL);
		$this->ectemplates->assign('mid', $mid);
		$this->ectemplates->assign('tsn', $tsn);
		$this->ectemplates->assign('tab', $tab);
		$this->ectemplates->display('article/article_batadd_doc');
	}

	function ondocedit() {
		parent::start_template();
		$tab = $this->fun->accept('tab', 'R');
		$tab = empty($tab) ? 'true' : $tab;

		$did = intval($this->fun->accept('did', 'R'));
		if (empty($did)) exit('false');
		$docview = $this->get_document($did);
		if (empty($docview['color'])) {
			$docview['color'] = $this->CON['input_color'];
		}
		if(!empty($docview['startdate'])) {
			$docview['startdate'] = date('Y-m-d',$docview['startdate']);
		}
		if(!empty($docview['enddate'])) {
			$docview['enddate'] = date('Y-m-d',$docview['enddate']);
		}
		$mid = empty($docview['mid']) ? 0 : $docview['mid'];

		$lng = $docview['lng'];

		$typelist = $this->get_typeselect($mid, 0, $docview['tid'], $lng, 0, 1);
		$this->ectemplates->assign('typelist', $typelist);

		$extid_array = !empty($docview['extid']) ? explode(',', $docview['extid']) : array();
		$this->ectemplates->assign('extid', $extid_array);

		$memberpuv = $this->get_member_purview_array($docview['purview']);
		$this->ectemplates->assign('memberpuvlist', $memberpuv['list']);

		$attrread = $this->get_modelatt($mid, false);
		if (!empty($docview['value'])) {
			$value = unserialize($docview['value']);
			unset($docview['value']);
			foreach ($value as $key => $valarr) {
				$value[$key] = $this->fun->br2nl($valarr);
			}
		}
		$attlist = array();
		if (is_array($attrread)) {
			$attlist = $this->fun->array_merge($attrread, $value);
		}
		$this->ectemplates->assign('attrread', $attlist);

		$modelview = $this->get_modelview($mid);
		$this->ectemplates->assign('modelview', $modelview);

		$subjectlistarray = $this->get_subjectlist_array($docview['sid'], $mid, $lng);
		$this->ectemplates->assign('subjectlistarray', $subjectlistarray['list']);

		$formarray = $this->get_form_array($docview['fgid'], $lng);
		$this->ectemplates->assign('formarray', $formarray['list']);

		$keytypearray = $this->get_keytype_array($docview['ktid'], $lng);
		$this->ectemplates->assign('keyarray', $keytypearray['list']);

		$piclist = $this->get_album_array($did);
		$piclist['num'] = $piclist['num'] + 1;
		$this->ectemplates->assign('picarray', $piclist['list']);
		$this->ectemplates->assign('piccount', $piclist['num']);

		$doclabel = $this->get_doclabel_array($docview['recommend'], $mid);
		$this->ectemplates->assign('doclabel', $doclabel['list']);
		$input_default = $this->CON;
		$this->ectemplates->assign('defaultinput', $input_default);
		$this->ectemplates->assign('lng', $lng);
		$this->ectemplates->assign('view', $docview);
		$this->ectemplates->assign('path', admin_URL);
		$this->ectemplates->assign('mid', $mid);
		$this->ectemplates->assign('tab', $tab);
		$this->ectemplates->display('article/article_edit_doc');
	}

	function ondocbatsave() {
		parent::start_pagetemplate();
		$inputclass = $this->fun->accept('inputclass', 'P');
		$lng = $this->fun->accept('lng', 'P');
		$mid = intval($this->fun->accept('mid', 'P'));
		$tid = intval($this->fun->accept('tid', 'P'));
		$sid = intval($this->fun->accept('sid', 'P'));
		$extid = $this->fun->accept('extid', 'P');
		$extid = is_array($extid) ? implode(',', $extid) : 0;

		$fname = $_FILES['batfile']['tmp_name'];
		if (empty($fname)) {
			exit('false');
		}

		$handle = @fopen($fname, 'r');

		$attrread = $this->get_modelatt($mid, false);

		$aid = $this->esp_adminuserid;

		$isclass = $this->esp_inputclassid;
		$isclass = empty($isclass) ? 0 : $isclass;

		$input_click = $this->CON['input_click'];
		$input_click = empty($input_click) ? 0 : $input_click;

		$typeview = $this->get_type($tid);

		$type_styleid = $typeview['styleid'];

		$read_templates = $typeview['readtemplate'];

		$filenamestyle = $typeview['filenamestyle'];

		$readnamestyle = $typeview['readnamestyle'];

		$dirname = $typeview['dirname'];

		$dirpath = $typeview['dirpath'];

		$isdatadir = $typeview['isdatadir'];

		$db_table = db_prefix . 'document';
		$db_table1 = db_prefix . 'document_content';
		$db_table2 = db_prefix . 'document_other';
		$db_table3 = db_prefix . 'document_value';
		$time = time();

		$db_field = 'lng,pid,mid,aid,tid,extid,sid,fgid,linkdid,isclass,islink,ishtml,ismess,isorder,ktid,purview,istemplates,recommend,tsn,title,longtitle,color,author,source,pic,tags,keywords,description,link,oprice,bprice,click,addtime,uptime,template,filename';

		for ($i = 0; $data = $this->fun->fgetcsv_reg($handle); $i++) {
			if ($i > 0) {
				$purview = intval($this->fun->daddslashes($data[0], 1));
				$tsn = $this->fun->daddslashes($data[1], 1);
				$title = $this->fun->daddslashes($data[2], 1);
				$showpic = $this->fun->daddslashes($data[3], 1);
				$recommend = $this->fun->daddslashes($data[4], 1);
				$isorder = intval($this->fun->daddslashes($data[5], 1));
				$isorder = empty($isorder) ? 0 : $isorder;
				$oprice = $this->fun->daddslashes($data[6], 1);
				$oprice = empty($oprice) ? 0 : $oprice;
				$bprice = $this->fun->daddslashes($data[7], 1);
				$bprice = empty($bprice) ? 0 : $bprice;
				$content = $this->fun->daddslashes($data[8], 1);
				$keywords = $this->fun->daddslashes($data[9], 1);
				$value = $this->fun->daddslashes($data[10], 1);

				$db_values = "'$lng',50,$mid,$aid,$tid,'$extid',$sid,0,'',$isclass,0,0,0,$isorder,0,$purview,0,'$recommend','$tsn','$title','','','','','$showpic','','$keywords','','',$oprice,$bprice,$input_click,$time,$time,'$read_templates',''";

				$this->db->query('INSERT INTO ' . $db_table . ' (' . $db_field . ') VALUES (' . $db_values . ')');
				$insert_id = $this->db->insert_id();
				if (empty($insert_id)) {
					exit('false');
				}

				$db_field_content = 'did,content';
				$db_values_content = "$insert_id,'$content'";
				$this->db->query('INSERT INTO ' . $db_table1 . ' (' . $db_field_content . ') VALUES (' . $db_values_content . ')');

				if (!empty($value) && !empty($insert_id)) {
					$modelvalue = split("\n", $value);
					$modelarray = array();
					foreach ($attrread as $key => $value) {
						if ($value['inputtype'] == 'checkbox') {
							$modelarray[$value['attrname']] = explode('/', $modelvalue[$key]);
						} else {
							$modelarray[$value['attrname']] = $modelvalue[$key];
						}
					}
					if (!empty($modelarray) && is_array($modelarray)) {
						$db_field_model = 'did,value';
						$model_value = addslashes(serialize($modelarray));
						$db_values_model = "$insert_id,'$model_value'";
						$this->db->query('INSERT INTO ' . $db_table3 . ' (' . $db_field_model . ') VALUES (' . $db_values_model . ')');
					}
				}
			}
		}
		exit('true');
	}
	//接收文章的参数，编辑或者添加等
	function ondocsave() {
		parent::start_pagetemplate();
		$inputclass = $this->fun->accept('inputclass', 'P');
		$lng = $this->fun->accept('lng', 'P');
		$mid = intval($this->fun->accept('mid', 'P'));
		$modelisorder = $this->fun->accept('modelisorder', 'P');
		$modelistime = $this->fun->accept('modelistime', 'P');
		$modelislongtitle = $this->fun->accept('modelislongtitle', 'P');
		$modelistsn = $this->fun->accept('modelistsn', 'P');
		$modelisauthor = $this->fun->accept('modelisauthor', 'P');
		$tid = intval($this->fun->accept('tid', 'P'));
		$extid = $this->fun->accept('extid', 'P');
		$extid = is_array($extid) ? implode(',', $extid) : 0;
		$sid = intval($this->fun->accept('sid', 'P'));
		$fgid = intval($this->fun->accept('fgid', 'P'));
		$purview = intval($this->fun->accept('purview', 'P'));

		$tsn = $this->fun->accept('tsn', 'P');
		if (empty($tsn)) {
			$tsn = $this->fun->get_tsn();
		}
		$title = $this->fun->accept('title', 'P');
		$color = $this->fun->accept('color', 'P');
		if ($color == $this->CON['input_color']) {
			$color = '';
		}
		$longtitle = $this->fun->accept('longtitle', 'P');
		$author = $this->fun->accept('author', 'P');
		$source = $this->fun->accept('source', 'P');
		$showpic = $this->fun->accept('showpic', 'P');

		$pic = $this->fun->accept('pic', 'P');
		if (is_array($pic) && count($pic) > 2) {

			$pic = array_unique($pic);
			$showpic = empty($showpic) ? $pic[0] : $showpic;
		}
		$islink = $this->fun->accept('islink', 'P');
		$islink = empty($islink) ? 0 : $islink;
		$link = $this->fun->accept('link', 'P');
		$ishtml = intval($this->fun->accept('ishtml', 'P'));
		$ishtml = empty($ishtml) ? 0 : $ishtml;
		$recommend = $this->fun->accept('recommend', 'P');
		if (!empty($recommend)) {
			$recommend = implode(',', $recommend);
		}
		$content = $this->fun->accept('content', 'P');
		$isorder = intval($this->fun->accept('isorder', 'P'));
		$isorder = empty($isorder) ? 0 : $isorder;
		$oprice = $this->fun->accept('oprice', 'P');
		$oprice = empty($oprice) ? 0 : $oprice;
		$bprice = $this->fun->accept('bprice', 'P');
		$bprice = empty($bprice) ? 0 : $bprice;
		
		/*会展信息*/
		$modelisexhibit = $this->fun->accept('modelisexhibit', 'P');
		$province  = intval($this->fun->accept('citytwo', 'P'));
		$province = empty($province) ? 0 : $province;
		$city = intval($this->fun->accept('citythree', 'P'));
		$city = empty($city) ? 0 : $city;
		$heldareas = $this->fun->accept('heldareas', 'P');
		$heldareas = empty($heldareas) ? '' : $heldareas;
		$lnglat = $this->fun->accept('lnglat', 'P');
		$lnglat = empty($lnglat) ? '' : $lnglat;
		
		$startdate = $this->fun->accept('startdate', 'P');
		$startdate = empty($startdate) ? 0 : strtotime($startdate);
		$enddate = $this->fun->accept('enddate', 'P');
		$enddate = empty($enddate) ? 0 : strtotime($enddate);
		$industry = intval($this->fun->accept('industry', 'P'));
		$industry = empty($industry) ? 0 : $industry;
		$venueaddress = $this->fun->accept('venueaddress', 'P');
		$venueaddress = empty($venueaddress) ? '' : $venueaddress;
		
		$other = $this->fun->accept('other', 'P');

		$modelatt = $this->fun->accept('modelatt', 'P');

		if (is_array($modelatt)) {
			foreach ($modelatt as $key => $value) {
				$modelatt[$key] = nl2br($value);
			}
		}

		$attrread = $this->get_modelatt($mid, false);

		$attreandcheckbox = $this->checkboxarray($attrread);
		if (is_array($attreandcheckbox)) {
			foreach ($attreandcheckbox as $key => $value) {
				$modelatt[$value] = $this->fun->accept($value, 'P');
			}
		}

		$click = intval($this->fun->accept('click', 'P'));
		$click = empty($click) ? 0 : $click;
		$addtime = $this->fun->accept('addtime', 'P');
		$tags = $this->fun->accept('tags', 'P');
		$keywords = $this->fun->accept('keywords', 'P');
		$description = $this->fun->accept('description', 'P');

		$istemplates = $this->fun->accept('istemplates', 'P');
		$template = $this->fun->accept('template', 'P');

		$filename = $this->fun->accept('filename', 'P');

		$linkdid = $this->fun->accept('linkdid', 'P');

		$input_isdellink = $this->CON['input_isdellink'];

		if ($input_isdellink == 1 && !empty($content)) {
			$content = $this->fun->linkclear($content);
		}

		$input_iskey = $this->CON['input_iskey'];

		$input_isdes = $this->CON['input_isdes'];

		$input_isdescription = $this->CON['input_isdescription'];
		$input_isdescription = empty($input_isdescription) ? 200 : ($input_isdescription > 200) ? 200 : $input_isdescription;

		$input_iskeyword = $this->CON['input_iskeyword'];
		$input_iskeyword = empty($input_iskeyword) ? 10 : ($input_iskeyword > 10) ? 10 : $input_iskeyword;

		if (empty($click)) {
			$input_click = $this->CON['input_click'];
			$click = empty($input_click) ? 0 : $input_click;
		}

		$is_keylink = $this->CON['is_keylink'];

		$is_html = $this->CON['is_html'];

		$file_htmldir = $this->CON['file_htmldir'];

		if ($is_keylink == 1 && !empty($content) && !empty($tags)) {
			$content = $this->rep_keylink($content, $tags, $lng);
		}
		if (empty($tid)) exit($this->lng['article_js_tid_empty']);

		$typeview = $this->get_type($tid);

		$type_styleid = $typeview['styleid'];

		$read_templates = ($istemplates) ? $template : $typeview['readtemplate'];

		$filenamestyle = $typeview['filenamestyle'];

		$readnamestyle = $typeview['readnamestyle'];

		$dirname = $typeview['dirname'];

		$dirpath = $typeview['dirpath'];

		$isdatadir = $typeview['isdatadir'];

		$aid = $this->esp_adminuserid;

		$isclass = $this->esp_inputclassid;
		$isclass = empty($isclass) ? 0 : $isclass;
		$db_table = db_prefix . 'document';
		$db_table1 = db_prefix . 'document_content';
		$db_table2 = db_prefix . 'document_other';
		$db_table3 = db_prefix . 'document_value';
		$db_table4 = db_prefix . 'document_exhibition'; //会展信息
		$time = time();
		$addtime = empty($addtime) ? $time : strtotime($addtime);
		if ($inputclass == 'add') {
			$this->powercheck(60, 67);

			if (!empty($tags)) {
				$this->install_tags($tags, $lng);
			}

			if (empty($description) && $input_isdescription > 0 && $input_isdes == 1 && !empty($content)) {
				$description = $this->fun->get_substr($content, $input_isdescription);
			}

			if (empty($keywords) && $input_iskeyword > 0 && $input_iskey == 1 && !empty($content)) {
				$keywords = $this->get_keyword($content, $input_iskeyword);
				$keywords = $this->fun->daddslashes($keywords, 1);
			}
			$description = $this->fun->daddslashes($description, 1);

			$db_field = 'lng,pid,mid,aid,tid,extid,sid,fgid,linkdid,isclass,islink,ishtml,ismess,isorder,ktid,purview,istemplates,recommend,tsn,title,
				longtitle,color,author,source,pic,tags,keywords,description,link,oprice,bprice,click,addtime,uptime,template,filename';
			$db_values = "'$lng',50,$mid,$aid,$tid,'$extid',$sid,$fgid,'$linkdid',$isclass,$islink,$ishtml,0,$isorder,0,$purview,$istemplates,'$recommend','$tsn','$title',
				'$longtitle','$color','$author','$source','$showpic','$tags','$keywords','$description','$link',$oprice,$bprice,
				$click,$addtime,$time,'$read_templates','$filename'";
			$this->db->query('INSERT INTO ' . $db_table . ' (' . $db_field . ') VALUES (' . $db_values . ')');
			$insert_id = $this->db->insert_id();
			
			$db_field = 'did,province,city,heldareas,lnglat,startdate,enddate,industry,venueaddress';
			$db_values = "$insert_id,$province,$city,'$heldareas','$lnglat',$startdate,$enddate,$industry,'$venueaddress'";
			$this->db->query('INSERT INTO ' . $db_table4 . ' (' . $db_field . ') VALUES (' . $db_values . ')');

			$db_field = 'did,content';
			$db_values = "$insert_id,'$content'";

			$this->db->query('INSERT INTO ' . $db_table1 . ' (' . $db_field . ') VALUES (' . $db_values . ')');
			if ($modelistime == 1) {

				$other['startime'] = empty($other['startime']) ? 0 : intval($this->fun->formatdate($other['startime'], 4));
				$other['endtime'] = empty($other['endtime']) ? 0 : intval($this->fun->formatdate($other['endtime'], 4));
				$other['width'] = empty($other['width']) ? 0 : intval($other['width']);
				$other['istime'] = empty($other['istime']) ? 0 : intval($other['istime']);
				$other['height'] = empty($other['height']) ? 0 : intval($other['height']);
				$other['filetype'] = empty($other['filetype']) ? 0 : intval($other['filetype']);
				$db_field = 'did,startime,endtime,width,height,istime,filetype';
				$db_values = "$insert_id,$other[startime],$other[endtime],$other[width],$other[height],$other[istime],$other[filetype]";
				$this->db->query('INSERT INTO ' . $db_table2 . ' (' . $db_field . ') VALUES (' . $db_values . ')');
			}
			if (!empty($modelatt) && is_array($modelatt)) {

				$db_field = 'did,value';
				$value = addslashes(serialize($modelatt));
				$db_values = "$insert_id,'$value'";
				$this->db->query('INSERT INTO ' . $db_table3 . ' (' . $db_field . ') VALUES (' . $db_values . ')');
			}

			$this->install_pic($insert_id, $pic, false);

			$htmlid = $this->articlehtml($insert_id);
			$delindex = admin_ROOT . "html/". $this->CON['entrance_file'] .'.'.$this->CON['file_fileex'];
			if (file_exists($delindex)) {
				$this->fun->delfile($delindex);
			}
			$this->writelog($this->lng['article_add_log'], $this->lng['log_extra_ok'] . ' id=' . $insert_id);
			if ($htmlid['c'] == 1) {

				$returmess = $this->lng['article_js_doc_add_html_err2'] . '(' . $htmlid['s'] . ')';
				exit($returmess);
			} elseif ($htmlid['c'] == 2) {

				$returmess = $this->lng['filedircreat_err'] . '(' . $htmlid['s'] . ')';
				exit($returmess);
			} elseif ($htmlid['c'] == 3) {

				$returmess = $this->lng['filedir_err'] . '(' . $htmlid['s'] . ')';
				exit($returmess);
			} elseif ($htmlid['c'] == 4) {

				$returmess = $this->lng['article_js_doc_add_html_err'] . '(' . $htmlid['s'] . ')';
				exit($returmess);
			} elseif ($htmlid['c'] == 0) {
				exit('true');
			}
		} elseif ($inputclass == 'edit') {
			$this->powercheck(57, 86);
			$did = $this->fun->accept('did', 'P');
			if (empty($did)) {
				exit($this->lng['article_js_doc_add_html_err3']);
			}
			$filepath = $this->fun->accept('filepath', 'P');

			if ($ishtml == 1 && $is_html == 1 && $islink == 0) {
				$readfileArray = array('dirname' => $dirname, 'tid' => $tid, 'did' => $did, 'datetime' => date("YmdHis"));

				$filename = empty($filename) ? $this->get_htmlfilename($readnamestyle, $readfileArray) : $filename;

				$filepath_temp = ($isdatadir == 1) ? $dirpath . '/' . date("Ymd") : $dirpath;
				$filepath = empty($filepath) ? $filepath_temp : $filepath;
			}
			$db_where = 'did=' . $did;

			$db_set = "aid=$aid,tid=$tid,extid='$extid',sid=$sid,fgid=$fgid,linkdid='$linkdid',islink=$islink,ishtml=$ishtml,isorder=$isorder,purview=$purview,istemplates=$istemplates,recommend='$recommend',tsn='$tsn',title='$title',
				longtitle='$longtitle',color='$color',author='$author',source='$source',pic='$showpic',tags='$tags',keywords='$keywords',description='$description',
				link='$link',oprice=$oprice,bprice=$bprice,click=$click,addtime=$addtime,uptime=$time,template='$read_templates',filename='$filename',filepath='$filepath'";

			$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);

			$db_set = "content='$content'";
			$this->db->query('UPDATE ' . $db_table1 . ' SET ' . $db_set . ' WHERE ' . $db_where);
			
			$db_set = "province=$province,city=$city,heldareas='$heldareas',lnglat='$lnglat',startdate=$startdate,enddate=$enddate,industry=$industry,venueaddress='$venueaddress'";
			
			$this->db->query('UPDATE ' . $db_table4 . ' SET ' . $db_set . ' WHERE ' . $db_where);

			if ($modelistime == 1) {

				$other['startime'] = empty($other['startime']) ? 0 : intval($this->fun->formatdate($other['startime'], 4));
				$other['endtime'] = empty($other['endtime']) ? 0 : intval($this->fun->formatdate($other['endtime'], 4));
				$other['width'] = empty($other['width']) ? 0 : intval($other['width']);
				$other['istime'] = empty($other['istime']) ? 0 : intval($other['istime']);
				$other['height'] = empty($other['height']) ? 0 : intval($other['height']);
				$other['filetype'] = empty($other['filetype']) ? 0 : intval($other['filetype']);

				if ($this->checkdid($did, 'document_other')) {
					$db_set = "startime=$other[startime],endtime=$other[endtime],width=$other[width],height=$other[height],istime=$other[istime],filetype=$other[filetype]";
					$this->db->query('UPDATE ' . $db_table2 . ' SET ' . $db_set . ' WHERE ' . $db_where);
				} else {
					$db_field = 'did,startime,endtime,width,height,istime,filetype';
					$db_values = "$did,$other[startime],$other[endtime],$other[width],$other[height],$other[istime],$other[filetype]";
					$this->db->query('INSERT INTO ' . $db_table2 . ' (' . $db_field . ') VALUES (' . $db_values . ')');
				}
			}

			if (!empty($modelatt) && is_array($modelatt)) {

				$value = addslashes(serialize($modelatt));
				if ($this->checkdid($did, 'document_value')) {
					$db_set = "value='$value'";
					$this->db->query('UPDATE ' . $db_table3 . ' SET ' . $db_set . ' WHERE ' . $db_where);
				} else {
					$db_field = 'did,value';
					$db_values = "$did,'$value'";
					$this->db->query('INSERT INTO ' . $db_table3 . ' (' . $db_field . ') VALUES (' . $db_values . ')');
				}
			}

			$this->install_pic($did, $pic);

			$htmlid = $this->articlehtml($did);
			$this->dbcache->clearcache('document_' . $did, true);
			$delindex = admin_ROOT . "html/". $this->CON['entrance_file'] .'.'.$this->CON['file_fileex'];
			if (file_exists($delindex)) {
				$this->fun->delfile($delindex);
			}
			$this->writelog($this->lng['article_edit_log'], $this->lng['log_extra_ok'] . ' id=' . $did);
			if ($htmlid['c'] == 1) {

				$returmess = $this->lng['article_js_doc_add_html_err2'] . '(' . $htmlid['s'] . ')';
				exit($returmess);
			} elseif ($htmlid['c'] == 2) {

				$returmess = $this->lng['filedircreat_err'] . '(' . $htmlid['s'] . ')';
				exit($returmess);
			} elseif ($htmlid['c'] == 3) {

				$returmess = $this->lng['filedir_err'] . '(' . $htmlid['s'] . ')';
				exit($returmess);
			} elseif ($htmlid['c'] == 4) {

				$returmess = $this->lng['article_js_doc_add_html_err'] . '(' . $htmlid['s'] . ')';
				exit($returmess);
			} elseif ($htmlid['c'] == 0) {
				exit('true');
			}
		}
	}

	function ondel() {
		$this->powercheck(57, 82);
		$db_table = db_prefix . 'document';
		$db_table2 = db_prefix . 'document_album';
		$db_table3 = db_prefix . 'document_content';
		$db_table4 = db_prefix . 'document_other';
		$db_table5 = db_prefix . 'document_value';
		$selectinfoid = $this->fun->accept('articleselectinfoid', 'P');
		if (empty($selectinfoid)) exit('false');

		$file_htmldir = $this->CON['file_htmldir'];
		$htmdirpath = admin_ROOT . $file_htmldir;

		if (is_dir($htmdirpath)) {
			if (!$this->fun->filemode($htmdirpath)) {
				exit('false');
			}
		}
		$infoarray = explode(',', $selectinfoid);
		$count = count($infoarray) - 1;
		if ($count <= 0) exit('false');
		for ($i = 0; $i < $count; $i++) {
			$db_where = "did=$infoarray[$i]";
			$relist = $this->get_documentview($infoarray[$i]);
			if ($relist['islink'] == 0 && $relist['ishtml'] == 1) {
				if ($this->CON['is_alonelng']) {
					$filepath = $htmdirpath . $relist['filepath'] . '/' . $relist['filename'] . '.' . $this->CON['file_fileex'];
				} else {
					$filepath = $htmdirpath . $relist['lng'] . '/' . $relist['filepath'] . '/' . $relist['filename'] . '.' . $this->CON['file_fileex'];
				}
				$this->fun->delfile($filepath);
			}
			$this->db->query('DELETE FROM ' . $db_table . ' WHERE ' . $db_where);
			$this->db->query('DELETE FROM ' . $db_table2 . ' WHERE ' . $db_where);
			$this->db->query('DELETE FROM ' . $db_table3 . ' WHERE ' . $db_where);
			$this->db->query('DELETE FROM ' . $db_table4 . ' WHERE ' . $db_where);
			$this->db->query('DELETE FROM ' . $db_table5 . ' WHERE ' . $db_where);
		}
		$delindex = admin_ROOT . "html/" . $this->CON['entrance_file'] .'.'.$this->CON['file_fileex'];
		if (file_exists($delindex)) {
			$this->fun->delfile($delindex);
		}
		$this->writelog($this->lng['article_del_log'], $this->lng['log_extra_ok'] . ' id=' . $selectinfoid);
		exit('true');
	}

	function onsort() {
		$this->powercheck(57, 84);
		$db_table = db_prefix . 'document';
		$id = $this->fun->accept('infoid', 'P');
		$pid = $this->fun->accept('pid', 'P');
		$idArray = explode(',', $id);
		$pidArray = explode(',', $pid);
		foreach ($idArray as $key => $value) {
			if (!empty($value)) {
				$db_where = "did=$value";
				$db_set = "pid=$pidArray[$key]";
				$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
			}
		}
		$this->writelog($this->lng['article_sort_log'], $this->lng['log_extra_ok']);
		exit('true');
	}

	function onsetting() {
		$this->powercheck(57, 83);
		$db_table = db_prefix . 'document';
		$selectinfoid = $this->fun->accept('articleselectinfoid', 'P');
		$selectinfoid = $selectinfoid . '0';
		if (empty($selectinfoid)) exit('false');
		$value = $this->fun->accept('value', 'P');
		$dbname = $this->fun->accept('dbname', 'P');
		$db_set = "$dbname=$value";
		$db_where = "did IN ( $selectinfoid )";
		$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
		$this->writelog($this->lng['article_setting_log'], $this->lng['log_extra_ok'] . ' id=' . $selectinfoid);
		exit('true');
	}

	function checkdid($did, $dbname) {
		$db_table = db_prefix . $dbname;
		$db_where = " WHERE did='$did'";
		$countnum = $this->db_numrows($db_table, $db_where);
		if ($countnum > 0) {
			return true;
		} else {
			return false;
		}
	}

	function oncreathtml() {
		$this->powercheck(57, 85);
		$is_html = $this->CON['is_html'];
		if ($is_html == 0) exit('false');
		$selectinfoid = $this->fun->accept('articleselectinfoid', 'P');
		if (empty($selectinfoid)) exit('false');
		$infoarray = explode(',', $selectinfoid);
		$count = count($infoarray) - 1;
		if ($count <= 0) exit('false');
		for ($i = 0; $i < $count; $i++) {
			$this->articlehtml($infoarray[$i]);
		}
		$this->writelog($this->lng['article_htmlcreat_botton'], $this->lng['log_extra_ok']);
		exit('true');
	}

}
?>